package com.nondo.dean.platform.controller.api.app;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.common.web.View;
import com.nondo.dean.platform.domain.SystemArticle;
import com.nondo.dean.platform.service.SystemArticleService;

@RestController("apiAppPlatformSystemArticle")
@RequestMapping("/{v}/app/system/article")
public class SystemArticleController {
    @Autowired
    SystemArticleService systemArticleService;

    /**
     * 查看文章详情
     * @param request
     * @param response
     * @param id
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/info/{id}")
    public View<SystemArticle> info(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Integer id) {
        View<SystemArticle> view = new View<SystemArticle>(20000, "获取数据成功");
        
        SystemArticle article = null;
        if (id != null) {
            article = systemArticleService.select(id);
        } else {
            article = new SystemArticle();
        }

        view.setData(article);
        return view;
    }
    
    /**
     * 查看相关文章
     * @param request
     * @param response
     * @param type
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/{type}")
    public View<SystemArticle> info(HttpServletRequest request, HttpServletResponse response, @PathVariable("type") String type) {
        View<SystemArticle> view = new View<SystemArticle>(20000, "获取数据成功");
        
        SystemArticle article = null;
        if (type != null) {
            article = systemArticleService.selectByType(type);
        } else {
            article = new SystemArticle();
        }

        view.setData(article);
        return view;
    }
    
}
